{% extends 'admin/common/base.html' %}
{% block css %}
{{super()}}
<link href="{{url_for('admin.static',filename='ajax/libs/select2/select2.min.css')}}?v=4.0.13" rel="stylesheet" />
<link href="{{url_for('admin.static',filename='ajax/libs/select2/select2-bootstrap.min.css')}}?v=4.0.13" rel="stylesheet" />
<style type="text/css">
    .select-table table {
        table-layout: fixed;
    }

    .table>thead>tr>th {
        text-align: center;
    }

    .select-table .table td {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .form-control {
        padding: 3px 6px 4px;
        height: 30px;
    }

    .icheckbox-blue {
        top: 0px;
        left: 6px;
    }

    .form-control.select2-hidden-accessible {
        position: static !important;
    }

    .select-table table label.error {
        position: inherit;
    }

    select+label.error {
        z-index: 1;
        right: 40px;
    }
</style>
{% endblock %}
{% block body %}

<body class="gray-bg"
    style="font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif !important;">
    <section class="section-content">
        <div class="row">
            <div class="col-xs-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content" style="border-style:none;">
                        <div class="nav-tabs-custom">
                            <ul class="nav nav-tabs">
                                <li><a href="#tab-basic" data-toggle="tab" aria-expanded="false">基本信息</a></li>
                                <li class="active"><a href="#tab-field" data-toggle="tab" aria-expanded="true">字段信息</a>
                                </li>
                                <li><a href="#tab-gen" data-toggle="tab" aria-expanded="false">生成信息</a></li>
                                <li class="pull-right header">
                                    <i class="fa fa-code"></i> 生成配置
                                </li>
                            </ul>
                            <form id="form-gen-edit" class="form-horizontal">
                                <input name="id" type="hidden" id="id" value="{{d.id}}" />
                                <div class="tab-content">
                                    <!-- 基本信息 -->
                                    <div class="tab-pane" id="tab-basic">
                                        <div class="row mt20">
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label is-required">名称：</label>
                                                    <div class="col-sm-8">
                                                        <input name="name" class="form-control" type="text"
                                                            placeholder="name" maxlength="200" required id="name"
                                                            value="{{d.name}}">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label is-required">实体Model：</label>
                                                    <div class="col-sm-8">
                                                        <input name="model" class="form-control" type="text"
                                                            placeholder="model" maxlength="200" required id="model"
                                                            value="{{d.model}}">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <div class="form-group">
                                                    <label class="col-xs-2 control-label">备注：</label>
                                                    <div class="col-xs-10">
                                                        <textarea name="remark" maxlength="500" class="form-control"
                                                            rows="3"></textarea>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- 字段信息 -->
                                    <div class="tab-pane active" id="tab-field">
                                        <div class="select-table table-striped"
                                            style="margin-top: 0px;padding-top: 0px;padding-bottom: 0px;">
                                            <table id="bootstrap-table" data-use-row-attr-func="true"
                                                data-reorderable-rows="true"></table>
                                        </div>
                                    </div>

                                    <!-- 生成信息 -->
                                    <div class="tab-pane" id="tab-gen">
                                        <div class="row mt20">
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label is-required">生成模板：</label>
                                                    <div class="col-sm-8">
                                                        <select class='form-control' id="tplCategory" name='tpl_category'
                                                            style="width: 100%">
                                                            <option value="crud" {{'selected' if d.tpl_category == 'crud' else ''}}>单表（增删改查）</option>
                                                            <option value="crud_html" {{'selected' if d.tpl_category == 'crud_html' else ''}}>单表（增删改查【html列表渲染】）</option>
                                                            <option value="tree" {{'selected' if d.tpl_category == 'tree' else ''}}>树表（增删改查）</option>
                                                            <option value="api" {{'selected' if d.tpl_category == 'api' else ''}}>api接口</option>
                                                            <option value="sub" {{'selected' if d.tpl_category == 'sub' else ''}}>主子表（增删改查）</option>
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label is-required"
                                                        title="生成在路径下，例如 edu/org">模板生成路径：<i
                                                            class="fa fa-question-circle-o"></i></label>
                                                    <div class="col-sm-8">
                                                        <input name="tpl_path" class="form-control" type="text"
                                                            placeholder="请输入路径" maxlength="100" required
                                                            id="tpl_path" value="{{d.tpl_path}}">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label is-required"
                                                        title="可理解为子系统名，例如 sys">生成模块名：<i
                                                            class="fa fa-question-circle-o"></i></label>
                                                    <div class="col-sm-8">
                                                        <input name="model_name" class="form-control" type="text"
                                                            placeholder="请输入生成模块名" maxlength="30" required
                                                            id="model_name" value="{{d.model_name}}">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label is-required"
                                                        title="view路径，例如 user">view路径：<i
                                                            class="fa fa-question-circle-o"></i></label>
                                                    <div class="col-sm-8">
                                                        <input name="view_path" class="form-control" type="text"
                                                            placeholder="view路径" maxlength="50" required
                                                            id="view_path" value="{{d.view_path}}">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-6">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label is-required" title="分配到指定菜单下，例如 系统管理">上级菜单：<i class="fa fa-question-circle-o"></i></label>
                                                    <div class="col-sm-8">
                                                        <input id="parentMenuId" name="parent_menu_id" type="hidden" value="{{d.parent_menu_id}}"/>
                                                        <div class="input-group">
                                                            <input id="parentMenuName" name="parent_menu_name" class="form-control" type="text" onclick="selectMenuTree()" placeholder="请选择上级菜单" maxlength="50" value="{{d.parent_menu_name}}" required>
                                                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-6">
                                            </div>
                                        </div>
                                        <div class="hidden row" id="pathinfo">
                                            <div class="col-sm-12">
                                                <div class="form-group">
                                                    <label class="col-xs-2 control-label"
                                                        title="填写磁盘绝对路径，若不填写，则生成到当前Web项目下">生成基础路径：<i
                                                            class="fa fa-question-circle-o"></i></label>
                                                    <div class="col-xs-10">
                                                        <div class="input-group input-group-sm">
                                                            <input id="genPath" name="genPath" class="form-control"
                                                                type="text" placeholder="请输入项目路径" maxlength="200"
                                                                value="/">
                                                            <div class="input-group-btn">
                                                                <button type="button"
                                                                    class="btn btn-default dropdown-toggle"
                                                                    data-toggle="dropdown">最近路径快速选择 <span
                                                                        class="caret"></span></button>
                                                                <ul class="dropdown-menu dropdown-menu-right"
                                                                    role="menu">
                                                                    <li><a href="javascript:$('#genPath').val('/')"><i
                                                                                class="fa fa-refresh"></i>恢复默认的生成基础路径</a>
                                                                    </li>
                                                                </ul>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="hidden" id="subInfo">
                                            <h4 class="form-header h4">关联信息</h4>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label class="col-sm-4 control-label is-required"
                                                            title="关联子表的表名， 如：sys_user">关联子表的表名：<i
                                                                class="fa fa-question-circle-o"></i></label>
                                                        <div class="col-sm-8">
                                                            <select class='type form-control' id="subTableName"
                                                                name='subTableName' style="width: 100%">
                                                                <option value="">---请选择---</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label class="col-sm-4 control-label is-required"
                                                            title="子表关联的外键名， 如：user_id">子表关联的外键名：<i
                                                                class="fa fa-question-circle-o"></i></label>
                                                        <div class="col-sm-8">
                                                            <select class='router form-control' id="subTableFkName"
                                                                name='subTableFkName' style="width: 100%">
                                                                <option value="">---请选择---</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="hidden" id="otherInfo">
                                            <h4 class="form-header h4">其他信息</h4>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label class="col-sm-4 control-label is-required"
                                                            title="树显示的编码字段名， 如：dept_id">树编码字段：<i
                                                                class="fa fa-question-circle-o"></i></label>
                                                        <div class="col-sm-8">
                                                            <select class='form-control' id="treeCode"
                                                                name='tree_code' style="width: 100%">
                                                                <option value="">---请选择---</option>
                                                                {% for col in columns %}
                                                                <option value="{{col.name}}" {{'selected' if col.name == d.tree_code else ''}}>{{col.name}}:{{col.comment}}</option>
                                                                {% endfor %}
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label class="col-sm-4 control-label is-required"
                                                            title="树显示的父编码字段名， 如：parent_Id">树父编码字段：<i
                                                                class="fa fa-question-circle-o"></i></label>
                                                        <div class="col-sm-8">
                                                            <select class='form-control' id="treeParentCode"
                                                                name='tree_parent_code' style="width: 100%">
                                                                <option value="">---请选择---</option>
                                                                {% for col in columns %}
                                                                <option value="{{col.name}}" {{'selected' if col.name == d.tree_parent_code else ''}}>{{col.name}}:{{col.comment}}</option>
                                                                {% endfor %}
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label class="col-sm-4 control-label is-required"
                                                            title="树节点的显示名称字段名， 如：dept_name">树名称字段：<i
                                                                class="fa fa-question-circle-o"></i></label>
                                                        <div class="col-sm-8">
                                                            <select class='form-control' id="treeName"
                                                                name='tree_name' style="width: 100%">
                                                                <option value="">---请选择---</option>
                                                                {% for col in columns %}
                                                                <option value="{{col.name}}" {{'selected' if col.name == d.tree_name else ''}}>{{col.name}}:{{col.comment}}</option>
                                                                {% endfor %}
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-sm-6">
                                                    <div class="form-group">
                                                        <label class="col-sm-4 control-label is-required"
                                                            title="排序字段， 如：order_num">排序字段：<i
                                                                class="fa fa-question-circle-o"></i></label>
                                                        <div class="col-sm-8">
                                                            <select class='form-control' id="tree_order"
                                                                name='tree_order' style="width: 100%">
                                                                <option value="">---请选择---</option>
                                                                {% for col in columns %}
                                                                <option value="{{col.name}}" {{'selected' if col.name == d.tree_order else ''}}>{{col.name}}:{{col.comment}}</option>
                                                                {% endfor %}
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="col-sm-offset-5 col-sm-6">
                            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i
                                    class="fa fa-check"></i>保 存</button>&nbsp;
                            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i
                                    class="fa fa-reply-all"></i>关 闭 </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</body>
{% endblock %}
{% block js %}
{{ super() }}
<script src="{{url_for('admin.static',filename='ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js')}}"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/select2/select2.min.js')}}?v=4.0.13"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/bootstrap-table/extensions/reorder-rows/bootstrap-table-reorder-rows.js')}}?v=1.18.3"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/bootstrap-table/extensions/reorder-rows/jquery.tablednd.js')}}?v=1.0.3"></script>
<script src="{{url_for('admin.static',filename='js/jquery.tmpl.js')}}"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/cxselect/jquery.cxselect.min.js')}}?v=1.4.2"></script>
<script>
    /* 用户信息-修改 */
    $("#form-table-edit").validate({
        rules: {
            tableName: {
                required: true,
            },
        },
        focusCleanup: true
    });

    /* 表级联信息 */
    var data = [{ "s": [{ "s": null, "v": "sessionId", "n": "sessionId\uFF1A\u7528\u6237\u4F1A\u8BDDid" }, { "s": null, "v": "login_name", "n": "login_name\uFF1A\u767B\u5F55\u8D26\u53F7" }, { "s": null, "v": "dept_name", "n": "dept_name\uFF1A\u90E8\u95E8\u540D\u79F0" }, { "s": null, "v": "ipaddr", "n": "ipaddr\uFF1A\u767B\u5F55IP\u5730\u5740" }, { "s": null, "v": "login_location", "n": "login_location\uFF1A\u767B\u5F55\u5730\u70B9" }, { "s": null, "v": "browser", "n": "browser\uFF1A\u6D4F\u89C8\u5668\u7C7B\u578B" }, { "s": null, "v": "os", "n": "os\uFF1A\u64CD\u4F5C\u7CFB\u7EDF" }, { "s": null, "v": "status", "n": "status\uFF1A\u5728\u7EBF\u72B6\u6001on_line\u5728\u7EBFoff_line\u79BB\u7EBF" }, { "s": null, "v": "start_timestamp", "n": "start_timestamp\uFF1Asession\u521B\u5EFA\u65F6\u95F4" }, { "s": null, "v": "last_access_time", "n": "last_access_time\uFF1Asession\u6700\u540E\u8BBF\u95EE\u65F6\u95F4" }, { "s": null, "v": "expire_time", "n": "expire_time\uFF1A\u8D85\u65F6\u65F6\u95F4\uFF0C\u5355\u4F4D\u4E3A\u5206\u949F" }], "v": "sys_user_online", "n": "sys_user_online\uFF1A\u5728\u7EBF\u7528\u6237\u8BB0\u5F55" }, { "s": [{ "s": null, "v": "user_id", "n": "user_id\uFF1A\u7528\u6237ID" }, { "s": null, "v": "role_id", "n": "role_id\uFF1A\u89D2\u8272ID" }], "v": "sys_user_role", "n": "sys_user_role\uFF1A\u7528\u6237\u548C\u89D2\u8272\u5173\u8054\u8868" }, { "s": [{ "s": null, "v": "role_id", "n": "role_id\uFF1A\u89D2\u8272ID" }, { "s": null, "v": "menu_id", "n": "menu_id\uFF1A\u83DC\u5355ID" }], "v": "sys_role_menu", "n": "sys_role_menu\uFF1A\u89D2\u8272\u548C\u83DC\u5355\u5173\u8054\u8868" }, { "s": [{ "s": null, "v": "oper_id", "n": "oper_id\uFF1A\u65E5\u5FD7\u4E3B\u952E" }, { "s": null, "v": "title", "n": "title\uFF1A\u6A21\u5757\u6807\u9898" }, { "s": null, "v": "business_type", "n": "business_type\uFF1A\u4E1A\u52A1\u7C7B\u578B\uFF080\u5176\u5B83 1\u65B0\u589E 2\u4FEE\u6539 3\u5220\u9664\uFF09" }, { "s": null, "v": "method", "n": "method\uFF1A\u65B9\u6CD5\u540D\u79F0" }, { "s": null, "v": "request_method", "n": "request_method\uFF1A\u8BF7\u6C42\u65B9\u5F0F" }, { "s": null, "v": "operator_type", "n": "operator_type\uFF1A\u64CD\u4F5C\u7C7B\u522B\uFF080\u5176\u5B83 1\u540E\u53F0\u7528\u6237 2\u624B\u673A\u7AEF\u7528\u6237\uFF09" }, { "s": null, "v": "oper_name", "n": "oper_name\uFF1A\u64CD\u4F5C\u4EBA\u5458" }, { "s": null, "v": "dept_name", "n": "dept_name\uFF1A\u90E8\u95E8\u540D\u79F0" }, { "s": null, "v": "oper_url", "n": "oper_url\uFF1A\u8BF7\u6C42URL" }, { "s": null, "v": "oper_ip", "n": "oper_ip\uFF1A\u4E3B\u673A\u5730\u5740" }, { "s": null, "v": "oper_location", "n": "oper_location\uFF1A\u64CD\u4F5C\u5730\u70B9" }, { "s": null, "v": "oper_param", "n": "oper_param\uFF1A\u8BF7\u6C42\u53C2\u6570" }, { "s": null, "v": "json_result", "n": "json_result\uFF1A\u8FD4\u56DE\u53C2\u6570" }, { "s": null, "v": "status", "n": "status\uFF1A\u64CD\u4F5C\u72B6\u6001\uFF080\u6B63\u5E38 1\u5F02\u5E38\uFF09" }, { "s": null, "v": "error_msg", "n": "error_msg\uFF1A\u9519\u8BEF\u6D88\u606F" }, { "s": null, "v": "oper_time", "n": "oper_time\uFF1A\u64CD\u4F5C\u65F6\u95F4" }], "v": "sys_oper_log", "n": "sys_oper_log\uFF1A\u64CD\u4F5C\u65E5\u5FD7\u8BB0\u5F55" }, { "s": [{ "s": null, "v": "user_id", "n": "user_id\uFF1A\u7528\u6237ID" }, { "s": null, "v": "dept_id", "n": "dept_id\uFF1A\u90E8\u95E8ID" }, { "s": null, "v": "login_name", "n": "login_name\uFF1A\u767B\u5F55\u8D26\u53F7" }, { "s": null, "v": "user_name", "n": "user_name\uFF1A\u7528\u6237\u6635\u79F0" }, { "s": null, "v": "user_type", "n": "user_type\uFF1A\u7528\u6237\u7C7B\u578B\uFF0800\u7CFB\u7EDF\u7528\u6237 01\u6CE8\u518C\u7528\u6237\uFF09" }, { "s": null, "v": "email", "n": "email\uFF1A\u7528\u6237\u90AE\u7BB1" }, { "s": null, "v": "phonenumber", "n": "phonenumber\uFF1A\u624B\u673A\u53F7\u7801" }, { "s": null, "v": "sex", "n": "sex\uFF1A\u7528\u6237\u6027\u522B\uFF080\u7537 1\u5973 2\u672A\u77E5\uFF09" }, { "s": null, "v": "avatar", "n": "avatar\uFF1A\u5934\u50CF\u8DEF\u5F84" }, { "s": null, "v": "password", "n": "password\uFF1A\u5BC6\u7801" }, { "s": null, "v": "salt", "n": "salt\uFF1A\u76D0\u52A0\u5BC6" }, { "s": null, "v": "status", "n": "status\uFF1A\u5E10\u53F7\u72B6\u6001\uFF080\u6B63\u5E38 1\u505C\u7528\uFF09" }, { "s": null, "v": "del_flag", "n": "del_flag\uFF1A\u5220\u9664\u6807\u5FD7\uFF080\u4EE3\u8868\u5B58\u5728 2\u4EE3\u8868\u5220\u9664\uFF09" }, { "s": null, "v": "login_ip", "n": "login_ip\uFF1A\u6700\u540E\u767B\u5F55IP" }, { "s": null, "v": "login_date", "n": "login_date\uFF1A\u6700\u540E\u767B\u5F55\u65F6\u95F4" }, { "s": null, "v": "pwd_update_date", "n": "pwd_update_date\uFF1A\u5BC6\u7801\u6700\u540E\u66F4\u65B0\u65F6\u95F4" }, { "s": null, "v": "create_by", "n": "create_by\uFF1A\u521B\u5EFA\u8005" }, { "s": null, "v": "create_time", "n": "create_time\uFF1A\u521B\u5EFA\u65F6\u95F4" }, { "s": null, "v": "update_by", "n": "update_by\uFF1A\u66F4\u65B0\u8005" }, { "s": null, "v": "update_time", "n": "update_time\uFF1A\u66F4\u65B0\u65F6\u95F4" }, { "s": null, "v": "remark", "n": "remark\uFF1A\u5907\u6CE8" }], "v": "sys_user", "n": "sys_user\uFF1A\u7528\u6237\u4FE1\u606F\u8868" }, { "s": [{ "s": null, "v": "job_log_id", "n": "job_log_id\uFF1A\u4EFB\u52A1\u65E5\u5FD7ID" }, { "s": null, "v": "job_name", "n": "job_name\uFF1A\u4EFB\u52A1\u540D\u79F0" }, { "s": null, "v": "job_group", "n": "job_group\uFF1A\u4EFB\u52A1\u7EC4\u540D" }, { "s": null, "v": "invoke_target", "n": "invoke_target\uFF1A\u8C03\u7528\u76EE\u6807\u5B57\u7B26\u4E32" }, { "s": null, "v": "job_message", "n": "job_message\uFF1A\u65E5\u5FD7\u4FE1\u606F" }, { "s": null, "v": "status", "n": "status\uFF1A\u6267\u884C\u72B6\u6001\uFF080\u6B63\u5E38 1\u5931\u8D25\uFF09" }, { "s": null, "v": "exception_info", "n": "exception_info\uFF1A\u5F02\u5E38\u4FE1\u606F" }, { "s": null, "v": "create_time", "n": "create_time\uFF1A\u521B\u5EFA\u65F6\u95F4" }], "v": "sys_job_log", "n": "sys_job_log\uFF1A\u5B9A\u65F6\u4EFB\u52A1\u8C03\u5EA6\u65E5\u5FD7\u8868" }, { "s": [{ "s": null, "v": "notice_id", "n": "notice_id\uFF1A\u516C\u544AID" }, { "s": null, "v": "notice_title", "n": "notice_title\uFF1A\u516C\u544A\u6807\u9898" }, { "s": null, "v": "notice_type", "n": "notice_type\uFF1A\u516C\u544A\u7C7B\u578B\uFF081\u901A\u77E5 2\u516C\u544A\uFF09" }, { "s": null, "v": "notice_content", "n": "notice_content\uFF1A\u516C\u544A\u5185\u5BB9" }, { "s": null, "v": "status", "n": "status\uFF1A\u516C\u544A\u72B6\u6001\uFF080\u6B63\u5E38 1\u5173\u95ED\uFF09" }, { "s": null, "v": "create_by", "n": "create_by\uFF1A\u521B\u5EFA\u8005" }, { "s": null, "v": "create_time", "n": "create_time\uFF1A\u521B\u5EFA\u65F6\u95F4" }, { "s": null, "v": "update_by", "n": "update_by\uFF1A\u66F4\u65B0\u8005" }, { "s": null, "v": "update_time", "n": "update_time\uFF1A\u66F4\u65B0\u65F6\u95F4" }, { "s": null, "v": "remark", "n": "remark\uFF1A\u5907\u6CE8" }], "v": "sys_notice", "n": "sys_notice\uFF1A\u901A\u77E5\u516C\u544A\u8868" }, { "s": [{ "s": null, "v": "user_id", "n": "user_id\uFF1A\u7528\u6237ID" }, { "s": null, "v": "post_id", "n": "post_id\uFF1A\u5C97\u4F4DID" }], "v": "sys_user_post", "n": "sys_user_post\uFF1A\u7528\u6237\u4E0E\u5C97\u4F4D\u5173\u8054\u8868" }];
    $('#subInfo').cxSelect({
        selects: ['type', 'router'],
        jsonValue: 'v',
        data: data
    });

    function submitHandler() {


        //let columns = []
        //var form = document.getElementById("form-gen-edit");
        //var formData = new FormData(form);
        //for (var key of formData.keys()) {
        //    if(key.startsWith('columns')){
        //        let s = key + ' = ' + formData.get(key)
        //        console.log(s);
        //        // eval(s)
        //    }
        //}
        //console.log(columns)
        // return;

        if ($.validate.form()) {
            $.operate.saveTab("{{url_for('admin.sys.gencode.edit')}}", $("#form-gen-edit").serializeArray());
        }
    }

    $(function () {
        var options = {
            url: "{{url_for('admin.sys.gencode.columns')}}",
            sortName: "sort",
            sortOrder: "desc",
            height: $(window).height() - 166,
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            onLoadSuccess: onLoadSuccess,
            onReorderRow: onReorderRow,
            columns: [{
                title: "序号",
                width: "5%",
                formatter: function (value, row, index) {
                    // 编号隐藏域
                    var columnIdHtml = $.common.sprintf("<input type='hidden' name='columns[%s].id' value='%s'>", index, row.id);
                    // 排序隐藏域
                    var sortHtml = $.common.sprintf("<input type='hidden' name='columns[%s].order_num' value='%s' id='columns_order_num_%s'>", index, row.order_num, row.id);
                    return columnIdHtml + sortHtml + $.table.serialNumber(index);
                },
                cellStyle: function (value, row, index) {
                    return { css: { "cursor": "move" } };
                }
            },
            {
                field: 'col_name',
                title: '字段列名',
                width: "10%",
                class: "nodrag",
                cellStyle: function (value, row, index) {
                    return { css: { "cursor": "default" } };
                }
            },
            {
		        field: 'col_type',
		        title: '数据类型',
		        width: "10%",
		        class: "nodrag",
		        cellStyle: function(value, row, index) {
                    return { css: { "cursor": "default" } };
                }
		    },
            {
                field: 'col_comment',
                title: '字段描述',
                width: "10%",
                formatter: function (value, row, index) {
                    var html = $.common.sprintf("<input class='form-control' type='text' name='columns[%s].col_comment' value='%s'>", index, value);
                    return html;
                }
            },
            {
                field: 'is_insert',
                title: '插入',
                width: "5%",
                formatter: function (value, row, index) {
                    var isCheck = value == 1 ? 'checked' : '';
                    var html = $.common.sprintf("<label class='check-box'><input type='checkbox' name='columns[%s].is_insert' value='1' %s></label>", index, isCheck);
                    return html;
                }
            },
            {
                field: 'is_edit',
                title: '编辑',
                width: "5%",
                formatter: function (value, row, index) {
                    var isCheck = value == 1 ? 'checked' : '';
                    var html = $.common.sprintf("<label class='check-box'><input type='checkbox' name='columns[%s].is_edit' value='1' %s></label>", index, isCheck);
                    return html;
                }
            },
            {
                field: 'is_list',
                title: '列表',
                width: "5%",
                formatter: function (value, row, index) {
                    var isCheck = value == 1 ? 'checked' : '';
                    var html = $.common.sprintf("<label class='check-box'><input type='checkbox' name='columns[%s].is_list' value='1' %s></label>", index, isCheck);
                    return html;
                }
            },
            {
                field: 'is_query',
                title: '查询',
                width: "5%",
                formatter: function (value, row, index) {
                    var isCheck = value == 1 ? 'checked' : '';
                    var html = $.common.sprintf("<label class='check-box'><input type='checkbox' name='columns[%s].is_query' value='1' %s></label>", index, isCheck);
                    return html;
                }
            },
            {
		            field: 'queryType',
		            title: '查询方式',
		            width: "10%",
		            formatter: function (value, row, index) {
		            	let s = '<div>'
                        s += "<select class='form-control' name='columns["+index+"].query_type'>"
                        s += '<option value="EQ" '+ (value === 'EQ'? 'selected': '') +'>=</option>'
                        s += '<option value="NE" '+ (value === 'NE'? 'selected': '') +'>!=</option>'
                        s += '<option value="GT" '+ (value === 'GT'? 'selected': '') +'>></option>'
                        s += '<option value="GTE" '+ (value === 'GTE'? 'selected': '') +'>>=</option>'
                        s += '<option value="LT" '+ (value === 'LT'? 'selected': '') +'><</option>'
                        s += '<option value="LTE" '+ (value === 'LTE'? 'selected': '') +'><=</option>'
                        s += '<option value="LIKE" '+ (value === 'LIKE'? 'selected': '') +'>Like</option>'
                        s += '<option value="BETWEEN" '+ (value === 'BETWEEN'? 'selected': '') +'>Between</option>'
                        s += '</select>'
                        s += '</div>'
                        return s;
		        	}
		        },
            {
                field: 'is_required',
                title: '必填',
                width: "5%",
                formatter: function (value, row, index) {
                    var isCheck = value == 1 ? 'checked' : '';
                    var html = $.common.sprintf("<label class='check-box'><input type='checkbox' name='columns[%s].is_required' value='1' %s></label>", index, isCheck);
                    return html;
                }
            },
            {
                field: 'html_type',
                title: '显示类型',
                width: "12%",
                formatter: function (value, row, index) {
                    let s = '<div>'
                    s += "<select class='form-control' name='columns["+index+"].html_type'>"
                    s+= '<option value="input" '+ (value === 'input'? 'selected': '') +'>文本框</option>'
                    s+= '<option value="textarea" '+(value === 'textarea'? 'selected': '')+'>文本域</option>'
                    s+= '<option value="select" '+(value === 'select'? 'selected': '')+'>下拉框</option>'
                    s+= '<option value="radio" '+(value === 'radio'? 'selected': '')+'>单选框</option>'
                    s+= '<option value="checkbox" '+(value === 'checkbox'? 'selected': '')+'>复选框</option>'
                    s+= '<option value="summernote" '+(value === 'summernote'? 'selected': '')+'>富文本</option>'
                    s+= '<option value="datetime" '+(value === 'datetime'? 'selected': '')+'>日期控件</option>'
                    s+= '<option value="upload" '+(value === 'upload'? 'selected': '')+'>文件上传</option>'
                    s+= '<option value="upload_img" '+(value === 'upload_img'? 'selected': '')+'>图片上传</option>'
                    s+= '</select>'
                    s+= '</div>'
                    return s;
                }
            },
            {
                field: 'dict_type',
                title: '字典类型',
                width: "13%",
                formatter: function (value, row, index) {
                    if(!value) {
                        value  = ''
                    }
                    console.log(value)
                    var html = $.common.sprintf("<input class='form-control' type='text' name='columns[%s].dict_type' value='%s' id='columns_dict_%s'>", index, value, row.id);
                    return "<div class='input-group'>" + html + "<span class='input-group-addon input-sm' onclick='selectDictTree(" + row.id + ", this)'><i class='fa fa-search'></i></span></div>";
                },
                cellStyle: function (value, row, index) {
                    return { css: { "cursor": "default" } };
                }
            }]
        };
        $.table.init(options);
    });

    // 当所有数据被加载时触发处理函数
    function onLoadSuccess(data) {
        $.fn.select2.defaults.set("theme", "bootstrap");
        $("select.form-control").each(function () {
            $(this).select2().on("change", function () {
                $(this).valid();
            })
        })
        $(".check-box").each(function () {
            $(this).iCheck({
                checkboxClass: 'icheckbox-blue'
            })
        })
    }

    // 当拖拽结束后处理函数
    function onReorderRow(data) {
        for (var i = 0; i < data.length; i++) {
            $("#columns_order_num_" + data[i].id).val(i + 1);
        }
    }

    $(function () {
        var tplCategory = $("#tplCategory option:selected").val();
        tplCategoryVisible(tplCategory);
        var genType = $('input[name="genType"]:checked').val();
        pathInfoVisible(genType);
    });

    $('#tplCategory').on('select2:select', function (event) {
        var tplCategory = $(event.target).val();
        tplCategoryVisible(tplCategory);
    });

    function tplCategoryVisible(tplCategory) {
        if ("crud" == tplCategory) {
            $("#treeCode").select2("val", [""]);
            $("#treeParentCode").select2("val", [""]);
            $("#treeName").select2("val", [""]);
            $('#tree_order').select2("val", [""]);
            $("#otherInfo").addClass("hidden");
            $("#subInfo").addClass("hidden");
        } else if ("tree" == tplCategory) {
            $("#otherInfo").removeClass("hidden");
            $("#treeCode").attr("required", "true");
            $("#treeParentCode").attr("required", "true");
            $("#treeName").attr("required", "true");
            $('#tree_order').attr('required', 'true');
            $("#subInfo").addClass("hidden");
        } else if ("sub" == tplCategory) {
            $("#subInfo").removeClass("hidden");
            $("#treeCode").select2("val", [""]);
            $("#treeParentCode").select2("val", [""]);
            $("#treeName").select2("val", [""]);
            $('#tree_order').select2("val", [""]);
            $("#subTableName").attr("required", "true");
            $("#subTableFkName").attr("required", "true");
            $("#otherInfo").addClass("hidden");
        }
    }

    $('input').on('ifChecked', function (event) {
        var genType = $(event.target).val();
        pathInfoVisible(genType);
    });

    function pathInfoVisible(genType) {
        if ("0" == genType) {
            $("#genPath").val("/");
            $("#pathinfo").addClass("hidden");
        } else if ("1" == genType) {
            $("#pathinfo").removeClass("hidden");
        }
    }

    // 选择字典处理函数
    function selectDictTree(id, obj) {
        var dictType = $.common.nullToStr($(obj).parent().find("input").val());
        var url = "{{url_for('admin.sys.gencode.select_dict_tree')}}?id=" + id + "&dict_type=" + dictType;
        var options = {
            title: '选择字典类型',
            width: "380",
            url: url,
            callBack: doDictSubmit
        };
        $.modal.openOptions(options);
    }

    // 选择菜单处理函数
    function selectMenuTree() {
        var parentMenuId = $("#parentMenuId").val();
        var menuId = parentMenuId > 0 ? parentMenuId : 1;
        var url = "{{url_for('admin.sys.menu.select_menu_tree')}}?id=" + menuId;
        var options = {
            title: '菜单选择',
            width: "380",
            url: url,
            callBack: doMenuSubmit
        };
        $.modal.openOptions(options);
    }

    function doDictSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        var columnId = body.find('#id').val();
        var dictType = body.find('#dictType').val();
        console.log(dictType)
        $.modal.close(index);
        $("#columns_dict_" + columnId).val(dictType);
    }

    function doMenuSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#parentMenuId").val(body.find('#treeId').val());
        $("#parentMenuName").val(body.find('#treeName').val());
        $.modal.close(index);
    }
</script>


{% endblock %}